package net.xm;

import java.util.List;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;


public class TodoList extends java.util.ArrayList<TodoListItem> {
	private static final long serialVersionUID = -1605610682116185855L;
	private String name;
	private String id;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public TodoListItem getItem(String id) {
		List<TodoListItem> all = this;
		for (TodoListItem item : all) {
			if(item.getId().equals(id)){
				return item;
			}
		}
		return null;
	}
	
	public TodoListItem getItemByContent(String content) {
		List<TodoListItem> all = this;
		for (TodoListItem item : all) {
			if(item.getContent().equals(content)){
				return item;
			}
		}
		return null;
	}
	
	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(Object object) {
		TodoList myClass = (TodoList) object;
		return new CompareToBuilder().append(this.name, myClass.name)
				.toComparison();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof TodoList)) {
			return false;
		}
		TodoList rhs = (TodoList) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(
				this.name, rhs.name).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(1894725335, -731133939).appendSuper(
				super.hashCode()).append(this.name).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("name", this.name).toString();
	}


	
	
}
